package com.infotec.ejemplospinner;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class MainActivity extends Activity {
	
	Spinner spclientes,spservidor;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		spclientes=(Spinner) findViewById(R.id.spinner1);
		spservidor=(Spinner) findViewById(R.id.spinner2);
		
		ArrayAdapter adapter=ArrayAdapter.createFromResource(this, R.array.clientes, android.R.layout.simple_spinner_dropdown_item);
		spclientes.setAdapter(adapter);
		final ArrayAdapter adapter2=ArrayAdapter.createFromResource(this, R.array.servidores_conuee, android.R.layout.simple_spinner_dropdown_item);
		final ArrayAdapter adapter3=ArrayAdapter.createFromResource(this, R.array.servidores_ses, android.R.layout.simple_spinner_dropdown_item);
		final ArrayAdapter adapter4=ArrayAdapter.createFromResource(this, R.array.servidores_sems, android.R.layout.simple_spinner_dropdown_item);
		spclientes.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parentView, View selectedItemView,
					int position, long id) {
				if(position==0){
					
					spservidor.setAdapter(adapter2);
				}
				else if(position==1){
					spservidor.setAdapter(adapter3);
				}
				else{
					spservidor.setAdapter(adapter4);
				}
					
				
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
